# -*- coding: utf-8 -*-

from app.module.admin import admin
from flask import render_template, redirect, url_for, request, flash
from app.service.common.auth import Auth as AuthService


@admin.route('/auth/login', methods=['GET', 'POST'])
def auth_login():
    if request.method == 'POST':
        rs = AuthService().login(request.form)
        if rs['c'] == 0:
            return redirect(url_for("admin.index"))
        else:
            flash(rs['m'])
            return redirect(url_for("admin.auth_login"))
    else:
        return render_template('admin/auth/login.html')


@admin.route('/auth/logout')
def auth_logout():
    AuthService().logout()
    return redirect(url_for('admin.auth_login'))


@admin.route('/auth/verify')
def auth_verify():
    return ''
